package com.work.principle.controller;

import com.work.principle.model.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-06-24
 * Time:16:56
 */
@RestController
public class DogController {
    @Autowired
    private ApplicationContext context;//注入Context

    @Autowired
    private Dog singletonDog;//注入对象

    @Autowired
    private Dog prototypeDog;

    @Autowired
    private Dog requestDog;

    @Autowired
    private Dog sessionDog;

    @Autowired
    private Dog ApplicationDog;

    @RequestMapping("/single")
    public String single(){
        //从context中去拿
        Dog contextDog = context.getBean("singletonDog",Dog.class);
        //从singletonDog中拿
        return "contextDog："+contextDog +"autowiredDog："+singletonDog;
    }

    @RequestMapping("/prototype")
    public String prototype(){
        //从context中去拿
        Dog contextDog = context.getBean("prototypeDog",Dog.class);
        //从prototypeDog中拿
        return "contextDog："+contextDog +",<br/>autowiredDog："+prototypeDog;
    }

    @RequestMapping("/request")
    public String request(){
        //从context中去拿
        Dog contextDog = context.getBean("requestDog",Dog.class);
        //从requestDog中拿
        return "contextDog："+contextDog +",<br/>autowiredDog："+requestDog;
    }

    @RequestMapping("/session")
    public String session(){
        //从context中去拿
        Dog contextDog = context.getBean("sessionDog",Dog.class);
        //从sessionDog中拿
        return "contextDog："+contextDog +",<br/>autowiredDog："+sessionDog;
    }

    @RequestMapping("/Application")
    public String Application(){
        //从context中去拿
        Dog contextDog = context.getBean("ApplicationDog",Dog.class);
        //从ApplicationDog中拿
        return "contextDog："+contextDog +",<br/>autowiredDog："+ApplicationDog;
    }
}
